﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows.Input;
using Gao.Poker.Command;
using Gao.Poker.Domain;
using Gao.Poker.Services;
using Gao.Poker.ViewModel;

namespace Gao.Poker.App.ViewModel
{
    public class ProductViewModel : BaseViewModel
    {
        public ICommand SaveCommand { get; set; }
        private List<Product> _products;
        private Product _product;
        public String ProductName { get; set; }

        public ProductViewModel()
        {
            SaveCommand = new ProductSaveCommand(SaveResult);
            ProductName = String.Empty;
        }

        public Product Product
        {
            get { return _product ?? (_product = new Product()); }
            set
            {
                _product = value;
                OnPropertyChanged("Product");
            }
        }

        public List<Product> Products
        {
            get
            {
                _products = new ProductService().SearchProducts(ProductName);
                return _products;
            }
        }

        private void SaveResult(bool obj, Product product)
        {
            if (obj)
            {
                OnPropertyChanged("Products");
                if (Message != null)
                    Message("数据保存成功");
            }
        }
    }
}
